Note: These instructions are same whether you are using Windows or Linux based Azure App Service.
- Follow the steps in this article on configuring SSL on Azure database for MySQL or PostgreSQL.
- Create a bin folder under D:/home/site/wwwroot and place the certificate (.pem file generated from step #1) in bin folder. You can do this directly by accessing the file server for web app using FTP or Git or Kudu .
- Log in to Azure portal.
- Select your existing Web app and click on Application settings. Add the following app setting for your web app:
For MYSQL :
For PostgreSQL :
- Now SSL certificate is added to your web application . Your application code needs to be updated to use this certificate authority when connecting to the database.
Connect to MySQL server with SSL for WordPress app
Add the following to wp-config.php to connect to the MySQL database via SSLdefine('MYSQL_CLIENT_FLAGS', MYSQL_CLIENT_SSL);
define( 'MYSQL_SSL_CA', getenv('MYSQL_SSL_CA'));
Note:
If you are using PHP 7.X version , you need another flagMYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT
for any PHP based application. For example with WordPress , you need to update MYSQL_CLIENT_FLAGS as shown below
define( 'MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT );
Connect to PostgreSQL server with SSL for Drupal app
Add the following to site/default/settings.php and add PDO options for SSL$databases = array (
'default' =>
array (
'default' =
array (
'database' => 'databasename',
'username' => 'username',
'password' => 'password',
'host' => 'hostname',
'port' => '3306',
'driver' => 'mysql',
'prefix' => '',
'pdo' => array(
PDO::PGSQL_ATTR_SSL_CA => getenv('POSTGRESQL_SSL_CA'),
),
),
);
Connect to MySQL server with SSL for Drupal app
Add the following to site/default/settings.php and add PDO options for SSL$databases = array ( 'default' => array ( 'default' => array ( 'database' => 'databasename', 'username' => 'username', 'password' => 'password', 'host' => 'hostname', 'port' => '3306', 'driver' => 'mysql', 'prefix' => '', 'pdo' => array( PDO::MYSQL_ATTR_SSL_CA => getenv('MYSQL_SSL_CA'), ), ), );
Connect to PostgreSQL server with SSL for Django app
Add the following to settings.py and the options for SSLDATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'dbname', 'USER': 'dbuser', 'PASSWORD': 'dbpassword', 'HOST': 'dbhost', 'OPTIONS': { 'sslmode': 'require', 'ca':os.environ.get('POSTGRESQL_SSL_CA', '') }, }, }